package com.zx.notification.common.mapstruct;

import com.zx.notification.common.enums.ChannelTypeEnum;
import com.zx.notification.common.enums.ConsumeModeEnum;
import com.zx.notification.common.enums.PushStatusEnum;
import com.zx.notification.common.enums.PushStrategyEnum;
import com.zx.notification.common.model.NotificationPushTasks;
import com.zx.notification.common.vo.NotificationPushTasksVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

/**
 * <p>
 * description: 通知推送任务映射器 <br>
 * create: 2025-10-17
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface NotificationPushTasksMapStructMapper {

    /**
     * 将NotificationPushTasks实体转换为NotificationPushTasksVO视图对象
     *
     * @param notificationPushTasks 通知推送任务实体
     * @return NotificationPushTasksVO视图对象
     */
    NotificationPushTasksVO notificationPushTasksToNotificationPushTasksVO(NotificationPushTasks notificationPushTasks);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param notificationPushTasks   通知推送任务实体
     * @param notificationPushTasksVO 通知推送任务VO
     */
    @AfterMapping
    default void setDescriptions(NotificationPushTasks notificationPushTasks, @MappingTarget NotificationPushTasksVO notificationPushTasksVO) {
        // 设置渠道类型描述
        ChannelTypeEnum channelTypeEnum = ChannelTypeEnum.getEnumByCode(notificationPushTasks.getChannelType());
        if (channelTypeEnum != null) {
            notificationPushTasksVO.setChannelTypeDesc(channelTypeEnum.getDesc());
        }

        // 设置消费模式描述
        ConsumeModeEnum consumeModeEnum = ConsumeModeEnum.getEnumByCode(notificationPushTasks.getConsumeMode());
        if (consumeModeEnum != null) {
            notificationPushTasksVO.setConsumeModeDesc(consumeModeEnum.getDesc());
        }

        // 设置状态描述
        PushStatusEnum pushStatusEnum = PushStatusEnum.getEnumByCode(notificationPushTasks.getStatus());
        if (pushStatusEnum != null) {
            notificationPushTasksVO.setStatusDesc(pushStatusEnum.getDesc());
        }

        // 设置推送策略描述
        PushStrategyEnum pushStrategyEnum = PushStrategyEnum.getEnumByCode(notificationPushTasks.getPushStrategy());
        if (pushStrategyEnum != null) {
            notificationPushTasksVO.setPushStrategyDesc(pushStrategyEnum.getDesc());
        }
    }
}